/**
 *	\file AKContainer.m
 *  
 *  \section desc_sec Description
 *  Description
 *  
 *  \if copyright
 *  	Copyright 2008 Ben Chen. All rights reserved.
 *  \endif
 *  
 *  \section hist_sec Change History:
 *  	-	1/19/08		BC		Created this file
 *  
 *  <hr>
 *  \addtogroup AnimalKingdom
 *  @{
 */

#import "AKContainer.h"

#import "AKBasicDrawing.h"
#import "AKInteractiveDrawing.h"

#import "AKBasicSoundProvider.h"

#import "AKDrawing.h"
#import "AKMediator.h"

#import "AKHumanPlayer.h"

#import "AKSoundController.h"

@implementation AKContainer

- (void)awakeFromNib
{
	unsigned int numOfPlayers = 2;
	NSArray *playerClassNamesArray = 
		[NSArray arrayWithObjects:@"AKHumanPlayer", @"AKHumanPlayer", nil];
//	NSArray *playerClassNamesArray = 
//	[NSArray arrayWithObjects:@"AKHumanPlayer", @"AKTTTAIPlayer", nil];
//	NSArray *playerClassNamesArray = 
//	[NSArray arrayWithObjects:@"AKTTTAIPlayer", @"AKTTTAIPlayer", nil];
	NSString *basicInfoStr		= @"AKTTTBasicInfoProvider";
	NSString *geometryStr		= @"AKTTTGeometryProvider";
	NSString *stateMaintainerStr= @"AKTTTStateMaintainer";
	NSString *imageProviderStr	= @"AKTTTImageProvider";
	NSString *aniProviderStr	= @"AKBasicAnimationProvider";

//	unsigned int numOfPlayers = 2;
//	NSArray *playerClassNamesArray = 
//	[NSArray arrayWithObjects:@"AKHumanPlayer", @"AKHumanPlayer", nil];
//	NSString *basicInfoStr		= @"AKOTBasicInfoProvider";
//	NSString *geometryStr		= @"AKOTGeometryProvider";
//	NSString *stateMaintainerStr= @"AKOTStateMaintainer";
//	NSString *imageProviderStr	= @"AKOTImageProvider";
//	NSString *aniProviderStr	= @"AKBasicAnimationProvider";
		
	// Create players
	int i = 0;
	NSMutableArray *players = [NSMutableArray array];
	for (NSString *playerClassName in playerClassNamesArray) {
		Class playerClass = NSClassFromString(playerClassName);
		id <AKPlayer> player = [[playerClass alloc] initWithSide:i 
													numOfPlayers:numOfPlayers];
		[players addObject:player];
		++i;
	}
	
	Class basicInfoClass		= NSClassFromString(basicInfoStr);
	Class geometryClass			= NSClassFromString(geometryStr);
	Class stateMaintainerClass	= NSClassFromString(stateMaintainerStr);
	Class imageProviderClass	= NSClassFromString(imageProviderStr);
	Class aniProviderClass		= NSClassFromString(aniProviderStr);
	
	id <AKBasicInfoProvider>  basicInfo		= [[basicInfoClass alloc] init];
	id <AKGeometryProvider>	  geometry		= [[geometryClass alloc] init];
	id <AKStateMaintainer>	stateMaintainer	= [[stateMaintainerClass alloc] init];
	id <AKImageProvider> imageProvider		= [[imageProviderClass alloc] init];
	id <AKAnimationProvider> aniProvider	= [[aniProviderClass alloc] init];
	
	AKDrawing *drawing = [[AKDrawing alloc] initWithImageProvider:imageProvider
												animationProvider:aniProvider
												 geometryProvider:geometry
												basicInfoProvider:basicInfo
														 drawView:drawingView];
	
	AKBasicSoundProvider *soundProvider = [[AKBasicSoundProvider alloc] init];
		
	for (id <AKPlayer> *aPlayer in players) {
		if ([(id)aPlayer isKindOfClass:[AKHumanPlayer class]]) {
			((AKHumanPlayer*)aPlayer).interactiveDrawing	= drawing;
			((AKHumanPlayer*)aPlayer).stateMaintainer		= stateMaintainer;
		}
	}
	
	AKSoundController *soundController = [[AKSoundController alloc] init];
	
	AKMediator *mediator = [[AKMediator alloc] initWithStateMaintainer:stateMaintainer
															   players:players
														  basicDrawing:drawing 
														 soundProvider:soundProvider 
													   soundController:soundController];
	[basicInfo			release];
	[geometry			release];
	[stateMaintainer	release];
	[imageProvider		release];
	[soundProvider		release];
	[soundController	release];
	
	NSSize boardSize = [geometry chessboardSize];

	[mainWindow setContentAspectRatio:boardSize];
	[mainWindow setContentSize:boardSize];
	[mainWindow center];
	
	[mediator start];	
}

@end

/** @} */
